package com.dog.basics.netty.business.impl;
import cn.hutool.core.util.ObjectUtil;
import com.dog.basics.netty.business.IBusinessServer;
import com.dog.basics.netty.protobuf.dto.DogNewsContentDto;
import com.dog.basics.netty.util.ConstantUtil;
import com.dog.basics.netty.util.SessionSocketHolder;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.log4j.Log4j2;

/**
 * @description: 未知请求响应
 * @author: He
 * @date: Created in 2020/10/8 18:43
 * @version: 1.0
 * @modified By:
 */
@Log4j2
public class ResponseHandlerImplUnknown implements IBusinessServer<DogNewsContentDto.Message> {

    /**
     * @功能描述: 未知请求响应
     * @author He
     * @date 2020/10/8
     */
    @Override
    public void businessHandler(ChannelHandlerContext ctx, DogNewsContentDto.Message msg) throws InterruptedException {
        log.info("未知请求响应:{}", msg.toString());
        ctx.channel().writeAndFlush(DogNewsContentDto.Message.newBuilder().setMsgType(ConstantUtil.UNKNOWN));
        // 判断如果没有登录则直接踢出登录
        if (ObjectUtil.isNull(SessionSocketHolder.getSession(ctx.channel().id().asLongText()))){
            ctx.channel().close();
        }

    }
}